package com.dream.service.impl;

import java.util.List;
import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dream.able.RlableMapper;
import com.dream.datasource.DBContextHolder;
import com.dream.pojo.Rlable;
import com.dream.pojo.RlableExample;
import com.dream.service.able.All_Service_able;

/*
 * 资源标签的业务类
 */
@Service("Rlable_Serviceimpl")
public class Rlable_Serviceimpl implements All_Service_able<Rlable> {

	/*
	 * 资源标签表DAO代理对象
	 */
	@Resource(name="rlableMapper")
	private RlableMapper rlable_mapper;
	/*
	 * (添加一个资源标签)
	 * @see com.dream.service.able.All_Serviceable#insert(java.lang.String[])
	 */
	@Override
	public Rlable insert(String... str) {
		//切换数据源,主库
		DBContextHolder.setDbType(DBContextHolder.master);
		//创建资源标签对象
		Rlable lable = new Rlable();
		//插入标签内容
		lable.setLable(str[0]);
		//插入状态
		lable.setState(1);
		//插入数据库
		return rlable_mapper.insertSelective(lable)>0?lable:null;
	}

	/*
	 * (查询所有可用的资源标签)
	 * @see com.dream.service.able.All_Serviceable#list()
	 */
	@Override
	public List<Rlable> list() {
		//切换数据源，从库
		DBContextHolder.setDbType(DBContextHolder.slave);
		//创建查询工具类
		RlableExample rlable_example = new RlableExample();
		//创建查询条件工具内部类
		RlableExample.Criteria criteria = rlable_example.createCriteria();
		//设置查询条件，state=1
		criteria.andStateEqualTo(1);
		//返回查询到的数据集
		return rlable_mapper.selectByExample(rlable_example);
	}

	@Override
	public Rlable getT(String... str) {
		// TODO Auto-generated method stub
		return null;
	}
}
